public class CustomerDomainTest {
    //Use class CustomerDomain automatically
    @Autowired
    CustomerDomain custDomain;

    Customer customer;
    Customer customer2;
    //Method gets executed before each test to create test objects
    @Before
    public void createCustomerObjects(){
        customer = new Customer();
        customer2 = new Customer();
        customer.setName("Hans Dampf");
        customer2.setName("Franz Hans");
    }
    //Denotes the method to be a Unit Test
    @Test
    public void testSaveCustomer() throws Exception {
        customer.setSex("W");
        customer.setName("Mata Hara");
        custDomain.saveCustomer(customer);
        //Assures given test value and actual value are the same.
        //Otherwise the Unit Test will fail.
        Assert.assertEquals(customer, custDomain.findCustomer(customer.getId()));
    }

    @Test
    public void testUpdateCustomer() throws Exception {
        custDomain.saveCustomer(customer);
        custDomain.saveCustomer(customer2);

        Assert.assertEquals(customer.getName(), custDomain.findCustomer(customer.getId()).getName());

        customer.setName("Max Mustermann");
        custDomain.updateCustomer(customer);

        Assert.assertEquals(customer.getName(), custDomain.findCustomer(customer.getId()).getName());
        Assert.assertNotEquals(customer.getName(), custDomain.findCustomer(customer2.getId()).getName());
    }
    //The test has to raise the specified business exception internally
    //in order to pass
    @Test(expected = CustomersHaveToHaveAtMostFirstAndLastName.class)
    public void testCreateCustomerMoreThanOneFirstOrLastName() throws Exception {
        customer.setName("Hans Mark Dampf");
        custDomain.saveCustomer(customer);
    }
    //Further Unit Tests here ...
}